var modify_tab;
Ext.onReady(function(){
		//添加自定义宾栏
		var advancedColumnWindow_ = new Ext.Window({	
			width:670,	
	    	height: 500,
	    	layout: "border",
	    	title:'添加自定义宾栏',
	    	modal: true,
	    	border:false,
	    	id: "customH_win_",
	    	closeAction: 'hide',
	    	listeners:{show:function(a){
				var customDropTarget1 = new Ext.dd.DropTarget(Ext.getCmp('selColumnColumn_simple_div_').getEl().dom, {
					ddGroup: 'customDDGroup',
					copy: false,
					notifyDrop: function(ddSource, e, data){
						node = ddSource.dragData.node;
						var a=Ext.getCmp('selColumnColumn_simple_');
						a.setValue(node.text);
						a.code=node.attributes.table+'.'+node.attributes.column;
						return(true);
				}
			}); 	
				var customDropTarget2 = new Ext.dd.DropTarget(Ext.getCmp('selColumnCondition_simple_div_').getEl().dom, {
					ddGroup: 'customDDGroup',
					copy: false,
					notifyDrop: function(ddSource, e, data){
					node = ddSource.dragData.node;
					var a=Ext.getCmp('selColumnCondition_simple_');
					a.setValue(a.getValue()+node.attributes.table+'.'+node.attributes.column);
					return(true);
				}
			});
			}},
		    items: [
		          {
						height:608,
						width:all_width * 20 / 100,
						autoScroll: true,
						collapsible: true,
						id: 'tree-panel-measures',
						region: 'west',
						title: '指标分类',
						enableDrag:true,
						ddGroup: 'customDDGroup',
						split: true,
						xtype: 'treepanel',
						margins: '2 2 2 2',
						useArrows:true,
						rootVisible : false,
						root: {text: '指标分类',draggable: false,id: '-1',isRoot:true},
						loader: new Ext.tree.TreeLoader({ 
								dataUrl: getRootPath()+'/matrixReport.report?decorate=no&isAjax=true&xmlName=MatrixReport',
								listeners:{beforeload:function(treeLoader, node){
										this.baseParams.xmlId = xml_id_;
										this.baseParams.tableName = node.attributes.tableName;
										this.baseParams.isRoot = node.attributes.isRoot;
										this.baseParams.isMeasures = 'true';//只显示事实表节点
										this.baseParams.pid = node.attributes.pid;
							   }}
						}),
						listeners:{
							beforeappend:function(tree,parent,node){
			         		//判断是否是报告期
								if(node.attributes.isTime=='true'){
									return false;	
								}else{
									return true;
								}
			         	}
						}
					}
		        ,{
		        	region:'center',
		        	width:320,
		        	height: 500,
		        	margins: '2 2 0 2',
		        	items:new Ext.TabPanel({
		        		activeTab: 0,
		        		items:[{
		        			title:'普通模式',
		        			style:'padding:15px',
		        			buttons:[{
		        				text:'保存',
		        				handler:function(){
				                   	 if(!Ext.getCmp('selColumnName_simple_').validate())
				                	 {
				                		return;
				                	 }
				                	 if(!Ext.getCmp('selColumnColumn_simple_').validate())
									 {
										return;
									 }
									 Ext.getCmp('customH_win_').hide();
									 var express = '';
									 if(Ext.getCmp('selColumnCondition_simple_').getValue().trim()==''){//无条件
										 express=Ext.getCmp('selColumnMethod_simple_').getValue()+'('+Ext.getCmp('selColumnColumn_simple_').code+')';
									 }else{
										 express=Ext.getCmp('selColumnMethod_simple_').getValue()+'(case when '+Ext.getCmp('selColumnCondition_simple_').getValue().trim()+' then '+Ext.getCmp('selColumnColumn_simple_').code+' end)';
									 }
									 jQuery("#droppableH").find('ul').append("<li isSimpleModel='true' selColumnColumnCode='"+Ext.getCmp('selColumnColumn_simple_').code+"' selColumnColumnName='"+Ext.getCmp('selColumnColumn_simple_').getValue()+"' selColumnColumnMethod='"+Ext.getCmp('selColumnMethod_simple_').getValue()+"' selColumnCondition=\""+Ext.getCmp('selColumnCondition_simple_').getValue().trim()+"\" oncontextmenu='showmenu(this)' ondblclick='modify(this);' label='"+Ext.getCmp('selColumnName_simple_').getValue()+"' customH='true' column='[customH]"+express+"' class='h'>"+Ext.getCmp('selColumnName_simple_').getValue()+"</li>");
		        				}
		        			},{
		        				text:'保存并继续添加',
		        				handler:function(){
			                   	 if(!Ext.getCmp('selColumnName_simple_').validate())
			                	 {
			                		return;
			                	 }
			                	 if(!Ext.getCmp('selColumnColumn_simple_').validate())
								 {
									return;
								 }
								 var express = '';
								 if(Ext.getCmp('selColumnCondition_simple_').getValue().trim()==''){//无条件
									 express=Ext.getCmp('selColumnMethod_simple_').getValue()+'('+Ext.getCmp('selColumnColumn_simple_').code+')';
								 }else{
									 express=Ext.getCmp('selColumnMethod_simple_').getValue()+'(case when '+Ext.getCmp('selColumnCondition_simple_').getValue().trim()+' then '+Ext.getCmp('selColumnColumn_simple_').code+' end)';
								 }
								 jQuery("#droppableH").find('ul').append("<li isSimpleModel='true' selColumnColumnCode='"+Ext.getCmp('selColumnColumn_simple_').code+"' selColumnColumnName='"+Ext.getCmp('selColumnColumn_simple_').getValue()+"' selColumnColumnMethod='"+Ext.getCmp('selColumnMethod_simple_').getValue()+"' selColumnCondition=\""+Ext.getCmp('selColumnCondition_simple_').getValue().trim()+"\" oncontextmenu='showmenu(this)' ondblclick='modify(this);' label='"+Ext.getCmp('selColumnName_simple_').getValue()+"' customH='true' column='[customH]"+express+"' class='h'>"+Ext.getCmp('selColumnName_simple_').getValue()+"</li>");
	        				}
		        			}],
		        			buttonAlign:'right',
		        			items:[{
		        				xtype:'fieldset',
		        				collapsible: true,
		        				title: '自定义宾栏名称',
		        				style:'padding:15px',
		        				height: 80,
		        				defaults:{labelWidth:60,layout:'form',border:false},
		        				items:[{
			        				items:[{
			        					id:'selColumnName_simple_',
				        				xtype:'textfield',
				        				fieldLabel:'宾栏名称',
				        				border:true,
				        				allowBlank:false,
				        				blankText:'宾栏名称不能为空',
				        				width:240
				        			}]
			        			}]
		        			},{
		        				xtype:'fieldset',
		        				title: '自定义宾栏配置',
		        				style:'padding:15px',
		        				height: 150,
		        	            collapsible: true,
		        				layout:'table',
			        			frame:true,
			        			layoutConfig: {columns:3},
			        			defaults:{labelWidth:60,layout:'form',border:false},
			        			items:[{
			        				id:'selColumnColumn_simple_div_',
			        				items:[{
			        					id:'selColumnColumn_simple_',
			        					xtype:'textfield',
			        					fieldLabel:'汇总列',
			        					blankText:'汇总列不能为空',
			        					allowBlank:false,
			        					readOnly:true,
			        					width:100
			        				}]
			        			},{
			        				width:10,
		        					border:false
			        			},{
			        				items:[{
			        					id:'selColumnMethod_simple_',
			        					xtype:'combo',
			        					fieldLabel:'汇总方式',
			        					store:new Ext.data.SimpleStore({
			        						fields: ['name', 'valtext'],
			        						data : [['sum','sum'],['avg', 'avg'],['count', 'count'],['max', 'max'],['min', 'min']]
			        					}),
			        					displayField:'name',
			        					mode: 'local',
			        					value:'sum',
			        					readOnly:true,
			        					valueField: "valtext",
			        					triggerAction: "all",
			        					width:60
			        				}]
			        			},{
			        				colspan:3,
			        				height:20,
		        					border:false
			        			},{
			        				id:'selColumnCondition_simple_div_',
			        				items:[{
			        					id:'selColumnCondition_simple_',
			        					xtype:'textfield',
			        					fieldLabel:'汇总条件',
			        					width:240
			        				}],
			        				colspan:3
			        			}]
		        			}]
		        		},
		        		{
		        		title:'高级模式',
		        		layout: 'table',
		        		border:false,
		        		bodyStyle:'padding:10px 10px 10px 20px',
		        		layoutConfig: {columns:5},
		        		defaults:{frame:false,style:'padding:2px',minWidth: '60',style:{marginBottom: '10px'}},
		        		items:[
        		         {
        		    	    id:'selColumnName_',
        		    	    xtype:'textfield',
        		    	    width  : 350,
        		    	    colspan:5,
        		    	    emptyText:'请输入自定义列名称',
        		    	    allowBlank:false,
        		    	    blankText:'自定义列名称不能为空'
        		         },
		        		 {
				            xtype: "textarea",
				            id: "selColumnSql_",
				            width  : 350,
				            height : 140,
				            enableKeyEvents: true,
				            hideLabel:true,
				            allowBlank:false,
				            blankText:'自定义列表达式不能为空',
				            colspan:5,
				            style: {
		        			 	marginBottom: '10px',
				                imeMode:'disabled'		//屏蔽输入法
				            },
				            listeners:
			            	{
			            		'render':function(e)
			            		{
			            			//屏蔽粘贴和鼠标右键
			            			//Ext.get('selColumnSql_').dom.oncontextmenu = function(e){return false;};
			            			//Ext.get('selColumnSql_').dom.onpaste = function(e){return false;};
			            		}
			            		,'keypress':function(e)
			            		{//屏蔽键盘按键
									//event.keyCode = 0;
									//event.returnvalue = false;
			            		}
			            		
			            	}
				        }		        		 
		        		 ,{
					        	xtype: "button",
			                    text: "sum",
			                    handler: function(){
			                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
			                    		if(node != null){
				                    		addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.column);
			                    		}else{
			                    			alert("请选择指标!");
			                    		}
			                    }
			                }
			                ,{
					        	xtype: "button",
			                    text: "avg",
			                    handler: function(){
			                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
			                    		if(node != null){
				                    		addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.column);
			                    		}else{
			                    			alert("请选择指标!");
			                    		}
			                    }
			                }
			                ,{
					        	xtype: "button",
			                    text: "count",
			                    handler: function(){
			                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
			                    		if(node != null){
				                    		addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.column);
			                    		}else{
			                    			alert("请选择指标!");
			                    		}
			                    }
			                }
			                ,{
					        	xtype: "button",
			                    text: "max",
			                    handler: function(){
		                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
		                    		if(node != null){
			                    		addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.column);
		                    		}else{
		                    			alert("请选择指标!");
		                    		}
			                    }
			                }
			                ,{
					        	xtype: "button",
			                    text: "min",
			                    handler: function(){
		                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
		                    		if(node != null){
			                    		addquery(this,'selColumnSql_',node.attributes.table+"."+node.attributes.column);
		                    		}else{
		                    			alert("请选择指标!");
		                    		}
			                    }
			                }
		        		 ,{
					        	xtype: "button",
			                    text: "c-sum",
			                    handler: function(){
		                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
		                    		if(node != null){
		                    			this.text="sum";
		                    			addquery(this,'selColumnSql_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
		                    		}else{
		                    			alert("请选择指标!");
		                    		}
			                    }
			             }
				        , {
				        	xtype: "button",
		                    text: "7",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
				        }
				        , {
				        	xtype: "button",
		                    text: "8",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "9",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " + ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		        		,{
					        	xtype: "button",
			                    text: "c-avg",
			                    handler: function(){
		                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
		                    		if(node != null){
		                    			this.text="avg";
		                    			addquery(this,'selColumnSql_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
		                    		}else{
		                    			alert("请选择指标!");
		                    		}
			                    }
			            }
		                , {
				        	xtype: "button",
		                    text: "4",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
				        }
		                ,{
				        	xtype: "button",
		                    text: "5",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "6",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " - ",
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		        		,{
				        	xtype: "button",
		                    text: "c-count",
		                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
	                    		if(node != null){
	                    			this.text="count";
	                    			addquery(this,'selColumnSql_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
		                    }
		        		}
		                ,{
				        	xtype: "button",
		                    text: "1",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "2",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "3",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " * ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		        		,{
				        	xtype: "button",
		                    text: "c-max",
		                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
	                    		if(node != null){
	                    			this.text="count";
	                    			addquery(this,'selColumnSql_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
		                    }
		        		}
		                ,{
				        	xtype: "button",
		                    text: "0",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: ".",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " % ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " / ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		        		,{
				        	xtype: "button",
		                    text: "c-min",
		                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
	                    		if(node != null){
	                    			this.text="min";
	                    			addquery(this,'selColumnSql_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
		                    }
		        		}
		                ,{
				        	xtype: "button",
		                    text: " ( ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: " ) ",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: "\'",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		                ,{
				        	xtype: "button",
		                    text: ",",
		                    style:
		                    {
		                    	marginBottom: '5px'
		                    },
		                    handler: function(){addquery(this,'selColumnSql_');}
		                }
		        		,{
				        	xtype: "button",
		                    text: "select",
		                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures').getSelectionModel().getSelectedNode();
	                    		if(node != null){
	                    			this.text=node.attributes.table+"."+node.attributes.column;
	                    			addquery(this,'selColumnSql_');
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
		                    }
		        		}
		                ,{
				        	xtype: "button",
		                    text: " 清除 ",
		                    handler: function(){
		                    		Ext.getCmp('selColumnSql_').setValue() == "";
										}
		                }
		                ,{
				        	xtype: "button",
		                    text: " 保存 ",
		                    handler: function(){
			                	 if(!Ext.getCmp('selColumnName_').validate())
			                	 {
			                		return;
			                	 }
			                	 if(!Ext.getCmp('selColumnSql_').validate())
								 {
									return;
								 }
								 Ext.getCmp('customH_win_').hide();
								 jQuery("#droppableH").find('ul').append("<li isAdvanceModel='true' oncontextmenu='showmenu(this)' ondblclick='modify(this);' label='"+Ext.getCmp('selColumnName_').getValue()+"' customH='true' column='[customH]"+Ext.getCmp('selColumnSql_').getValue()+"' class='h'>"+Ext.getCmp('selColumnName_').getValue()+"</li>");
		                    }
		                }
		                ,{
				        	xtype: "button",
		                    text: " 保存并继续添加 ",
		                    colspan:2,
		                    minWidth:130,
		                    handler: function(){
			                	 if(!Ext.getCmp('selColumnName_').validate())
			                	 {
			                		return;
			                	 }
			                	 if(!Ext.getCmp('selColumnSql_').validate())
								 {
									return;
								 }
			                	 jQuery("#droppableH").find('ul').append("<li isAdvanceModel='true' oncontextmenu='showmenu(this)' ondblclick='modify(this);' label='"+Ext.getCmp('selColumnName_').getValue()+"' customH='true' column='[customH]"+Ext.getCmp('selColumnSql_').getValue()+"' class='h'>"+Ext.getCmp('selColumnName_').getValue()+"</li>");
		                    }
		                }
		        		]
		        	}]})
		        }
		   		]
		 	});//Ext.Window
		//修改自定义宾栏
		modify_tab = new Ext.TabPanel({
    		activeTab: 0,
    		items:[{
    			title:'普通模式',
    			style:'padding:15px',
    			buttons:[{
    				text:'修改',
    				handler:function(){
	                   	 if(!Ext.getCmp('selColumnName_simple_modify_').validate())
	                	 {
	                		return;
	                	 }
	                	 if(!Ext.getCmp('selColumnColumn_simple_modify_').validate())
						 {
							return;
						 }
						 Ext.getCmp('customH_win_modify_').hide();
						 var express = '';
						 if(Ext.getCmp('selColumnCondition_simple_modify_').getValue().trim()==''){//无条件
							 express=Ext.getCmp('selColumnMethod_simple_modify_').getValue()+'('+Ext.getCmp('selColumnColumn_simple_modify_').code+')';
						 }else{
							 express=Ext.getCmp('selColumnMethod_simple_modify_').getValue()+'(case when '+Ext.getCmp('selColumnCondition_simple_modify_').getValue().trim()+' then '+Ext.getCmp('selColumnColumn_simple_modify_').code+' end)';
						 }
						 Ext.getCmp('customH_win_modify_').evObject.outerHTML = "<li isSimpleModel='true' selColumnColumnCode='"+Ext.getCmp('selColumnColumn_simple_modify_').code+"' selColumnColumnName='"+Ext.getCmp('selColumnColumn_simple_modify_').getValue()+"' selColumnColumnMethod='"+Ext.getCmp('selColumnMethod_simple_modify_').getValue()+"' selColumnCondition=\""+Ext.getCmp('selColumnCondition_simple_modify_').getValue().trim()+"\" oncontextmenu='showmenu(this)' ondblclick='modify(this);' label='"+Ext.getCmp('selColumnName_simple_modify_').getValue()+"' customH='true' column='[customH]"+express+"' class='h'>"+Ext.getCmp('selColumnName_simple_modify_').getValue()+"</li>";
    				}
    			}],
    			buttonAlign:'right',
    			items:[{
    				xtype:'fieldset',
    				collapsible: true,
    				title: '自定义宾栏名称',
    				style:'padding:15px',
    				height: 80,
    				defaults:{labelWidth:60,layout:'form',border:false},
    				items:[{
        				items:[{
        					id:'selColumnName_simple_modify_',
	        				xtype:'textfield',
	        				fieldLabel:'宾栏名称',
	        				border:true,
	        				allowBlank:false,
	        				blankText:'宾栏名称不能为空',
	        				width:240
	        			}]
        			}]
    			},{
    				xtype:'fieldset',
    				title: '自定义宾栏配置',
    				style:'padding:15px',
    				height: 150,
    	            collapsible: true,
    				layout:'table',
        			frame:true,
        			layoutConfig: {columns:3},
        			defaults:{labelWidth:60,layout:'form',border:false},
        			items:[{
        				id:'selColumnColumn_simple_div_modify_',
        				items:[{
        					id:'selColumnColumn_simple_modify_',
        					xtype:'textfield',
        					fieldLabel:'汇总列',
        					blankText:'汇总列不能为空',
        					allowBlank:false,
        					readOnly:true,
        					width:100
        				}]
        			},{
        				width:10,
    					border:false
        			},{
        				items:[{
        					id:'selColumnMethod_simple_modify_',
        					xtype:'combo',
        					fieldLabel:'汇总方式',
        					store:new Ext.data.SimpleStore({
        						fields: ['name', 'valtext'],
        						data : [['sum','sum'],['avg', 'avg'],['count', 'count'],['max', 'max'],['min', 'min']]
        					}),
        					displayField:'name',
        					mode: 'local',
        					value:'sum',
        					readOnly:true,
        					valueField: "valtext",
        					triggerAction: "all",
        					width:60
        				}]
        			},{
        				colspan:3,
        				height:20,
    					border:false
        			},{
        				id:'selColumnCondition_simple_div_modify_',
        				items:[{
        					id:'selColumnCondition_simple_modify_',
        					xtype:'textfield',
        					fieldLabel:'汇总条件',
        					width:240
        				}],
        				colspan:3
        			}]
    			}]
    		},{
    			title:'高级模式',
        		layout: 'table',
        		border:false,
        		bodyStyle:'padding:10px 10px 10px 20px',
        		layoutConfig: {columns:5},
        		defaults:{frame:false,style:'padding:2px',minWidth: '60',style:{marginBottom: '10px'}},
        		items:[
		         {
 		    	    id:'selColumnName_modify_',
 		    	    xtype:'textfield',
 		    	    width  : 350,
 		    	    colspan:5,
 		    	    emptyText:'请输入自定义列名称',
 		    	    allowBlank:false,
 		    	    blankText:'自定义列名称不能为空'
 		         },
	        		 {
			            xtype: "textarea",
			            id: "selColumnSql_modify_",
			            width  : 350,
			            height : 140,
			            enableKeyEvents: true,
			            hideLabel:true,
			            allowBlank:false,
			            blankText:'自定义列表达式不能为空',
			            colspan:5,
		            style: {
        			 	marginBottom: '10px',
		                imeMode:'disabled'		//屏蔽输入法
		            },
		            listeners:
	            	{
	            		'render':function(e)
	            		{
	            			//屏蔽粘贴和鼠标右键
	            			//Ext.get('selColumnSql_').dom.oncontextmenu = function(e){return false;};
	            			//Ext.get('selColumnSql_').dom.onpaste = function(e){return false;};
	            		}
	            		,'keypress':function(e)
	            		{//屏蔽键盘按键
							//event.keyCode = 0;
							//event.returnvalue = false;
	            		}
	            		
	            	}
		        }		        		 
        		 ,{
			        	xtype: "button",
	                    text: "sum",
	                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
	                    		if(node != null){
		                    		addquery(this,'selColumnSql_modify_',node.attributes.table+"."+node.attributes.column);
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
	                    }
	                }
	                ,{
			        	xtype: "button",
	                    text: "avg",
	                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
	                    		if(node != null){
		                    		addquery(this,'selColumnSql_modify_',node.attributes.table+"."+node.attributes.column);
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
	                    }
	                }
	                ,{
			        	xtype: "button",
	                    text: "count",
	                    handler: function(){
	                    		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
	                    		if(node != null){
		                    		addquery(this,'selColumnSql_modify_',node.attributes.table+"."+node.attributes.column);
	                    		}else{
	                    			alert("请选择指标!");
	                    		}
	                    }
	                }
	                ,{
			        	xtype: "button",
	                    text: "max",
	                    handler: function(){
                    		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
                    		if(node != null){
	                    		addquery(this,'selColumnSql_modify_',node.attributes.table+"."+node.attributes.column);
                    		}else{
                    			alert("请选择指标!");
                    		}
	                    }
	                }
	                ,{
			        	xtype: "button",
	                    text: "min",
	                    handler: function(){
                    		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
                    		if(node != null){
	                    		addquery(this,'selColumnSql_modify_',node.attributes.table+"."+node.attributes.column);
                    		}else{
                    			alert("请选择指标!");
                    		}
	                    }
	                }
        		 ,{
			        	xtype: "button",
	                    text: "c-sum",
	                    handler: function(){
                    		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
                    		if(node != null){
                    			this.text="sum";
                    			addquery(this,'selColumnSql_modify_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
                    		}else{
                    			alert("请选择指标!");
                    		}
	                    }
	             }
		        , {
		        	xtype: "button",
                    text: "7",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
		        }
		        , {
		        	xtype: "button",
                    text: "8",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: "9",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: " + ",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
        		,{
			        	xtype: "button",
	                    text: "c-avg",
	                    handler: function(){
                    		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
                    		if(node != null){
                    			this.text="avg";
                    			addquery(this,'selColumnSql_modify_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
                    		}else{
                    			alert("请选择指标!");
                    		}
	                    }
	            }
                , {
		        	xtype: "button",
                    text: "4",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
		        }
                ,{
		        	xtype: "button",
                    text: "5",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: "6",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: " - ",
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
        		,{
		        	xtype: "button",
                    text: "c-count",
                    handler: function(){
                		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
                		if(node != null){
                			this.text="count";
                			addquery(this,'selColumnSql_modify_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
                		}else{
                			alert("请选择指标!");
                		}
                    }
        		}
                ,{
		        	xtype: "button",
                    text: "1",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: "2",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: "3",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: " * ",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
        		,{
		        	xtype: "button",
                    text: "c-max",
                    handler: function(){
                		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
                		if(node != null){
                			this.text="count";
                			addquery(this,'selColumnSql_modify_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
                		}else{
                			alert("请选择指标!");
                		}
                    }
        		}
                ,{
		        	xtype: "button",
                    text: "0",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: ".",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: " % ",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: " / ",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
        		,{
		        	xtype: "button",
                    text: "c-min",
                    handler: function(){
                		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
                		if(node != null){
                			this.text="min";
                			addquery(this,'selColumnSql_modify_','case when '+node.attributes.table+"."+node.attributes.column+' > 0 then '+node.attributes.table+"."+node.attributes.column+' end');
                		}else{
                			alert("请选择指标!");
                		}
                    }
        		}
                ,{
		        	xtype: "button",
                    text: " ( ",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: " ) ",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: "\'",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
                ,{
		        	xtype: "button",
                    text: ",",
                    style:
                    {
                    	marginBottom: '5px'
                    },
                    handler: function(){addquery(this,'selColumnSql_modify_');}
                }
        		,{
		        	xtype: "button",
                    text: "select",
                    handler: function(){
                		var node = Ext.getCmp('tree-panel-measures-modify').getSelectionModel().getSelectedNode();
                		if(node != null){
                			this.text=node.attributes.table+"."+node.attributes.column;
                			addquery(this,'selColumnSql_modify_');
                		}else{
                			alert("请选择指标!");
                		}
                    }
        		}
                ,{
		        	xtype: "button",
                    text: " 清除 ",
                    handler: function(){
                    		Ext.getCmp('selColumnSql_modify_').setValue() == "";
								}
                }
                ,{
		        	xtype: "button",
                    text: " 修改 ",
                    handler: function(){
	                	 if(!Ext.getCmp('selColumnName_modify_').validate())
	                	 {
	                		return;
	                	 }
	                	 if(!Ext.getCmp('selColumnSql_modify_').validate())
						 {
							return;
						 }
						 Ext.getCmp('customH_win_modify_').hide();
						 Ext.getCmp('customH_win_modify_').evObject.outerHTML="<li isAdvanceModel='true' oncontextmenu='showmenu(this)' ondblclick='modify(this);' label='"+Ext.getCmp('selColumnName_modify_').getValue()+"' customH='true' column='[customH]"+Ext.getCmp('selColumnSql_modify_').getValue()+"' class='h'>"+Ext.getCmp('selColumnName_modify_').getValue()+"</li>";
                    }
                }
        		]
    	}]});
		var advancedColumnWindow_modify_ = new Ext.Window({	
			width:670,	
	    	height: 500,
	    	layout: "border",
	    	title:'修改自定义宾栏',
	    	evObject:null,
	    	modal: true,
	    	border:false,
	    	id: "customH_win_modify_",
	    	closeAction: 'hide',
	    	listeners:{show:function(a){
				var customDropTarget1 = new Ext.dd.DropTarget(Ext.getCmp('selColumnColumn_simple_div_modify_').getEl().dom, {
					ddGroup: 'customDDGroup',
					copy: false,
					notifyDrop: function(ddSource, e, data){
						node = ddSource.dragData.node;
						var a=Ext.getCmp('selColumnColumn_simple_modify_');
						a.setValue(node.text);
						a.code=node.attributes.table+'.'+node.attributes.column;
						return(true);
				}
			}); 	
				var customDropTarget2 = new Ext.dd.DropTarget(Ext.getCmp('selColumnCondition_simple_div_modify_').getEl().dom, {
					ddGroup: 'customDDGroup',
					copy: false,
					notifyDrop: function(ddSource, e, data){
					node = ddSource.dragData.node;
					var a=Ext.getCmp('selColumnCondition_simple_modify_');
					a.setValue(a.getValue()+node.attributes.table+'.'+node.attributes.column);
					return(true);
				}
			});
			}},
		    items: [
		          {
						height:608,
						width:all_width * 20 / 100,
						autoScroll: true,
						collapsible: true,
						id: 'tree-panel-measures-modify',
						region: 'west',
						title: '指标分类',
						enableDrag:true,
						ddGroup: 'customDDGroup',
						split: true,
						xtype: 'treepanel',
						margins: '2 2 2 2',
						useArrows:true,
						rootVisible : false,
						root: {text: '指标分类',draggable: false,id: '-1',isRoot:true},
						loader: new Ext.tree.TreeLoader({ 
								dataUrl: getRootPath()+'/matrixReport.report?decorate=no&isAjax=true&xmlName=MatrixReport',
								listeners:{beforeload:function(treeLoader, node){
										this.baseParams.xmlId = xml_id_;
										this.baseParams.tableName = node.attributes.tableName;
										this.baseParams.isRoot = node.attributes.isRoot;
										this.baseParams.isMeasures = 'true';//只显示事实表节点
										this.baseParams.pid = node.attributes.pid;
							   }}
						}),
						listeners:{
							beforeappend:function(tree,parent,node){
			         		//判断是否是报告期
								if(node.attributes.isTime=='true'){
									return false;	
								}else{
									return true;
								}
			         	}
						}
					}
		        ,{
		        	region:'center',
		        	width:320,
		        	height: 500,
		        	margins: '2 2 0 2',
		        	items:modify_tab
		        }
		   		]
		 	});//Ext.Window
		 	//自定义查询条件
 		var advancedQueryWindow_ = new Ext.Window({	
			title : '高级查询',	
			width: 670,
	        height: 450,
	        layout: "border",
	        modal: true,
	        id: "customH_condition_win_",
	        closeAction: 'hide',
		    items: [{
						height:608,
						width:all_width * 20 / 100,
						autoScroll: true,
						collapsible: true,
						id: 'tree-panel-measures1',
						region: 'west',
						title: '指标分类',
						ddGroup: 'DDGroup',
						split: true,
						xtype: 'treepanel',
						margins: '2 2 2 2',
						useArrows:true,
						rootVisible : false,
						root: {text: '指标分类',draggable: false,id: '-1',isRoot:true},
						loader: new Ext.tree.TreeLoader({ 
								dataUrl: getRootPath()+'/matrixReport.report?decorate=no&isAjax=true&xmlName=MatrixReport',
								listeners:{beforeload:function(treeLoader, node){
										this.baseParams.xmlId = xml_id_;
										this.baseParams.tableName = node.attributes.tableName;
										this.baseParams.isRoot = node.attributes.isRoot;
										this.baseParams.isMeasures = 'true';//只显示事实表节点
										this.baseParams.pid = node.attributes.pid;
							   }}
						}),
						listeners:{'click': function(node,e)
	            	{
	            		var o = new Object();
	            		o.text=node.attributes.table+'.'+node.attributes.column;
                    	addquery(o,"selQuerySql_");
	            	},
						beforeappend:function(tree,parent,node){
		         		//判断是否是报告期
							if(node.attributes.isTime=='true'){
								return false;	
							}else{
								return true;
							}
		         	}
	            	}
					}, 
	        {
	        	region:'center',
	        	title : '编辑器',
	        	width:320,
	        	height: 410,
	        	margins: '2 2 0 2',
	        	items:new Ext.Panel({
	        		layout: 'table',
	        		border:false,
	        		layoutConfig: {columns:5},
	        		defaults:{frame:false,width:40},
	        		items:[
	        		{
			            xtype: "textarea",
			            id: "selQuerySql_",
			            width  : 320,
			            height : 200,
			            value:'',
			            style: {
			                marginBottom: '10px'
			            },
			            colspan:5
			        }, {
			        	xtype: "button",
	                    text: " + ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
			        }, {
			        	xtype: "button",
	                    text: " - ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: " * ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: " / ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: " = ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: " < ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: " > ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                }, {
			        	xtype: "button",
	                    text: "%",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
			        }, {
			        	xtype: "button",
	                    text: " ( ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: " ) ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: "\'",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: ",",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: " IN ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                }, {
			        	xtype: "button",
	                    text: " AND ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
			        }, {
			        	xtype: "button",
	                    text: " OR ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                },{
			        	xtype: "button",
	                    text: " LIKE ",
	                    minWidth: '40',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");}
	                } 
	                ,{
			        	xtype: "button",
	                    text: " BETWEEN ",
	                    minWidth: '80',
	                    style: {
			                marginBottom: '5px'
			            },
	                    handler: function(){addquery(this,"selQuerySql_");},
	                    colspan:4
	                } 
	                ,{
	                	border:false,
	                	html:"",
	                	colspan:5
	                }
	                ,{
	                	border:false,
	                	html:"",
	                	colspan:1
	                }
	                ,{
			        	xtype: "button",
	                    text: " 保存 ",
	                    handler: function(){
	                    		Ext.getCmp('customH_condition_win_').hide();
	                    }
	                }
	                ,{
			        	xtype: "button",
	                    text: " 保存并预览 ",
	                    colspan:4,
	                    handler: function(){
	                    		Ext.getCmp('customH_condition_win_').hide();
	                    		Ext.getDom('preView').click();
	                    }
	                }
	        		]
	        	})
	        }
		]
		});//Ext.Window结束
		
		//设置自定义报告期
 		var custom_time_win_ = new Ext.Window({	
			title : '设置自定义报告期',	
			width: 600,
	        height: 350,
	        layout: "border",
	        modal: true,
	        id: "custom_time_win_",
	        closeAction: 'hide',
		    items: [{
						width:280,
						autoScroll: true,
						collapsible: true,
						id: 'tree-panel-measures2',
						region: 'west',
						title: '指标分类',
						ddGroup: 'DDGroup',
						split: true,
						xtype: 'treepanel',
						margins: '2 2 2 2',
						useArrows:true,
						rootVisible : false,
						root: {text: '指标分类',draggable: false,id: '-1',isRoot:true},
						loader: new Ext.tree.TreeLoader({ 
								dataUrl: getRootPath()+'/matrixReport.report?decorate=no&isAjax=true&xmlName=MatrixReport',
								listeners:{beforeload:function(treeLoader, node){
										this.baseParams.xmlId = xml_id_;
										this.baseParams.tableName = node.attributes.tableName;
										this.baseParams.isRoot = node.attributes.isRoot;
										this.baseParams.isMeasures = 'true';//只显示事实表节点
										this.baseParams.pid = node.attributes.pid;
							   }}
						}),
						listeners:{'click': function(node,e)
	            	{
	            		if(node.attributes.isTime)
	            			Ext.getCmp('property_time').setSource(
							      {      
						      		 '字段别名':node.text,
						             '字段名': node.attributes.column,
						             '表代码': node.attributes.table,
						             "报告期":typeof(node.attributes.time)=='undefined'?defaultDate:node.attributes.time
							      }
						      );
						    else
						    	Ext.getCmp('property_time').setSource(
							      {      
							      }
						      );
	            	},
						beforeappend:function(tree,parent,node){
		         		//判断是否是报告期
							if(node.attributes.isTime=='false'){
								return false;	
							}else{
								return true;
							}
		         	}
	            	}
					}, 
	        {
	        	region:'center',
	        	title : '选择报告期',
	        	width:320,
	        	id:'property_time',
	        	margins: '2 2 0 2',
	        	source: {
		      },
		      xtype:'propertygrid',
		      listeners:{
			      beforeedit:function(e){
			      	if(e.record.data.name!='报告期'){
					    	e.cancel=true;
					    	return false;
				    	}
			      },
			      validateedit:function(e){
			      	var prop=Ext.getCmp('property_time');
			      	prop.setSource(
				      	{
			             '字段别名':e.grid.store.getAt(e.grid.store.indexOfId("字段别名")).data.value,
			             '字段名': e.grid.store.getAt(e.grid.store.indexOfId("字段名")).data.value,
			             '表代码': e.grid.store.getAt(e.grid.store.indexOfId("表代码")).data.value,
			             "报告期":e.value.format('Ym')
			     			 }
			      	);
			      	Ext.getCmp('tree-panel-measures2').getSelectionModel().getSelectedNode().attributes.time=e.value.format('Ym');
			      	return false;
			      }
		      }
	        }
		]
		});//Ext.Window结束
		Ext.getCmp('property_time').customEditors['报告期']=new Ext.grid.GridEditor(
				new Ext.form.DateField({
								id:'aaa',
								value:'200805',
								format:"Ym" 
						  })
		);
})
	function addquery(o,sqlTextareaId,column)
	{
	    var tc = Ext.getDom(sqlTextareaId);
	    var tclen = tc.value.length;
	    tc.focus();
	    var str=o.text;
	    if(column)
	    	str+="("+column+")";
	    if(typeof document.selection != "undefined")
	    {
	        document.selection.createRange().text = str;  
	    }
	    else
	    {
	        tc.setValue(tc.value.substr(0,tc.selectionStart)+str+tc.value.substring(tc.selectionStart,tclen));
	    }
	}